#ifndef ASSEMBLE_H
#define ASSEMBLE_H

#include <Math.h>

typedef  __int64 bigInt;

#define NULL 0

inline int round(double v)
{
	return (int)(v + 0.5);
}

inline __int8 CIRToMin8(__int8 t)
{
	__asm
	{
		mov al, t
			mov bl,al
			mov cx,8
label1:
		ror al,1
			cmp al,bl
			jb label2
			jmp label3
label2:
		mov bl,al
label3:
		loop label1
			mov t,bl

	}
	return t;
}

inline __int16 CIRToMin16(__int16 t)
{
	__asm
	{
		mov ax, t
			mov bx,ax
			mov cx,16
label1:
		ror ax,1
			cmp ax,bx
			jb label2
			jmp label3
label2:
		mov bx,ax
label3:
		loop label1
			mov t,bx

	}
	return t;
}

inline __int32 CIRToMin32(__int32 t)
{
	__asm
	{
		mov eax, t
			mov ebx,eax
			mov ecx,16
label1:
		ror eax,1
			cmp eax,ebx
			jb label2
			jmp label3
label2:
		mov ebx,eax
label3:
		loop label1
			mov t,ebx

	}
	return t;

}
inline __int64 CIRToMin64(__int64 v)
{
	__asm{
		push ebp
			push edi
			xor ecx, ecx
			mov cl, 64
			lea edi, v
			mov eax, [edi]
		mov edx, [edi + 4]
$loop:
		clc
			rcl edx, 1
			rcl eax, 1
			adc edx, 0

			mov ebp, eax
			mov ebx, edx

			sub eax, [edi]
		sbb edx, [edi + 4]

		mov eax, ebp
			mov edx, ebx
			jae $next

			mov [edi], ebp
			mov [edi + 4], ebx

$next:
		loop $loop

			pop edi
			pop ebp
	}
	return v;
}


#endif